<?php

namespace App\Services\MakeMoment;


use App\Models\Moment;
use App\Http\Controllers\Api\V1\Requests\FormRequest;

class CommentMomentRequest extends FormRequest
{
	protected ?Moment $moment = null;

	public function rules(): array
	{
		
		$momentId =  (int)request('moment_id');
		if ($momentId) {
			$this->moment = Moment::find($momentId);
		}

		return [
			'moment_id' => ['required', $this->moment()],
			'content' => 'required|nullable|string',
		];
	}

	public function moment()
	{
		return function ($attribute, $value, $fail) {
			if (!$this->moment) {
				return $fail('该动态不存在');
			} 
			return true;
		};
	}



	public function getMoment(): Moment
	{
		return $this->moment;
	}
}
